﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using L = Science.Mathematics.LinearAlgebra;

namespace Strang3Ed.Chapter02.Section3
{
    public class ExampleA
    {
        public ExampleA()
        {
        }
        private string result;
        public string Result
        {
            get { return result; }
        }
        public void Compute()
        {
            double[,] x = {{1.0,0.0,0.0},
                           {-4.0,1.0,0.0},
                           {0.0,0.0,1.0}};

            L.Matrix E21 = new L.Matrix(x);

            double[,] y = {{1.0,0.0,0.0},
                           {0.0,0.0,1.0},
                           {0.0,1.0,0.0}};

            L.Matrix P32 = new L.Matrix(y);

            double[,] z = {{1.0,7.0,6.0},
                           {4.0,0.0,1.0},
                           {8.0,1.0,9.0}};

            L.Matrix A = new L.Matrix(z);


            L.Matrix E21A = E21 * A;

            L.Matrix AE21 = A * E21;

            result += E21A[0, 0].ToString() + "    ";
            result += E21A[0, 1].ToString() + "    ";
            result += E21A[0, 2].ToString() + "\r\n";

            result += E21A[1, 0].ToString() + "    ";
            result += E21A[1, 1].ToString() + "    ";
            result += E21A[1, 2].ToString() + "\r\n";

            result += E21A[2, 0].ToString() + "    ";
            result += E21A[2, 1].ToString() + "    ";
            result += E21A[2, 2].ToString() + "\r\n" + "\r\n";

            result += AE21[0, 0].ToString() + "    ";
            result += AE21[0, 1].ToString() + "    ";
            result += AE21[0, 2].ToString() + "\r\n";

            result += AE21[1, 0].ToString() + "    ";
            result += AE21[1, 1].ToString() + "    ";
            result += AE21[1, 2].ToString() + "\r\n";

            result += AE21[2, 0].ToString() + "    ";
            result += AE21[2, 1].ToString() + "    ";
            result += AE21[2, 2].ToString() + "\r\n" + "\r\n";



            L.Matrix P32A = P32 * A;

            L.Matrix AP32 = A * P32;


            result += P32A[0, 0].ToString() + "    ";
            result += P32A[0, 1].ToString() + "    ";
            result += P32A[0, 2].ToString() + "\r\n";

            result += P32A[1, 0].ToString() + "    ";
            result += P32A[1, 1].ToString() + "    ";
            result += P32A[1, 2].ToString() + "\r\n";

            result += P32A[2, 0].ToString() + "    ";
            result += P32A[2, 1].ToString() + "    ";
            result += P32A[2, 2].ToString() + "\r\n" + "\r\n";

            result += AP32[0, 0].ToString() + "    ";
            result += AP32[0, 1].ToString() + "    ";
            result += AP32[0, 2].ToString() + "\r\n";

            result += AP32[1, 0].ToString() + "    ";
            result += AP32[1, 1].ToString() + "    ";
            result += AP32[1, 2].ToString() + "\r\n";

            result += AP32[2, 0].ToString() + "    ";
            result += AP32[2, 1].ToString() + "    ";
            result += AP32[2, 2].ToString() + "\r\n" + "\r\n";
        }
    }
}
/*
1    7    6
0    -28    -23
8    1    9

-27    7    6
4    0    1
4    1    9

1    7    6
8    1    9
4    0    1

1    6    7
4    1    0
8    9    1
*/